/**
  ******************************************************************************
  * @file    gt32f030_crc.c
  * @author  GT Application Team
  * @version V1.0.0
  * @date    03-January-2025      
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2022 Giantec Semicondutor Inc</center></h2>
  *
  *             http://www.giantec-semi.com/
  *
  * Unless required by applicable law or agreed to in writing, software 
  * distributed under the License is distributed on an "AS IS" BASIS, 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "gt32f030_crc.h"
#include "gt32f030_rcc.h"

/** @addtogroup GT32F030_StdPeriph_Driver
  * @{
  */
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define CRC_Result_Flag   ((unsigned int)0x00010000)


/** @defgroup CRC 
  * @brief CRC driver modules
  * @{
  */ 

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/** @defgroup CRC_Private_Functions
  * @{
  */ 

/** @defgroup CRC_Init Initialization functions
 *  @brief   Initialization and functions
 *
@verbatim    
 ===============================================================================
              ##### Initialization functions #####
 ===============================================================================
@endverbatim
  * @{
  */
	
/**
  * @brief  Deinitializes CRC peripheral registers to their default reset 
  *         values.
  * @param  None
  * @retval None
  */
void CRC_DeInit(void)
{
	RCC_PeriphResetCmd(RCC_PeriphReset_CRC, ENABLE);
	RCC_PeriphResetCmd(RCC_PeriphReset_CRC, DISABLE);
}
/**
  * @}  
  */





/** @defgroup CRC_OpCfg Operation and Configuration functions
 *  @brief   Operation and Configuration functions
 *
@verbatim   
 ===============================================================================
           ##### Operation and Configuration functions #####
 ===============================================================================  
@endverbatim
  * @{
  */
/**
  * @brief  Resets the CRC Data register (DR).
  * @param  None
  * @retval None
  */
void CRC_ResetDR(void)
{
  /* Reset CRC generator */
  CRC_RESULT = 0xffff;
}

/**
  * @brief  Computes the 8-bit CRC of a given data word(8-bit).
  * @param  Data: data word(8-bit) to compute its CRC
  * @retval 16-bit CRC data
  */
unsigned short int CRC_CalcCRC_Uint8(unsigned char Data)
{
  CRC_DATA_8 = Data;
  
  return (unsigned short int)(CRC_RESULT&0xffff);
}


/**
  * @brief  Computes the 16-bit CRC of a given data word(16-bit).
  * @param  Data: data word(16-bit) to compute its CRC
  * @retval 16-bit CRC data
  */
unsigned short int CRC_CalcCRC_Uint16(unsigned short int Data)
{
  CRC_DATA_16 = Data;
  
  return (unsigned short int)(CRC_RESULT&0xffff);
}

/**
  * @brief  Computes the 32-bit CRC of a given data word(32-bit).
  * @param  Data: data word(32-bit) to compute its CRC
  * @retval 16-bit CRC data
  */
unsigned short int CRC_CalcCRC_Uint32(unsigned int Data)
{
  CRC_DATA_32 = Data;
  
  return (unsigned short int)(CRC_RESULT&0xffff);
}

/**
  * @brief  Computes the 8-bit CRC of a given buffer of data word(8-bit).
  * @param  pBuffer: pointer to the buffer containing the data to be computed
  * @param  BufferLength: length of the buffer to be computed					
  * @retval 32-bit CRC
  */
unsigned short int CRC_CalcBlockCRC(unsigned char pBuffer[], unsigned int BufferLength)
{
  unsigned int index = 0;
  
  for(index = 0; index < BufferLength; index++)
  {
    CRC_DATA_8 = pBuffer[index];
  }
  return (unsigned short int)(CRC_RESULT&0xffff);
}

/**
  * @brief  Returns the current CRC value.
  * @param  None
  * @retval 16-bit CRC
  */
unsigned short int CRC_GetCRC(void)
{
  return (unsigned short int)(CRC_RESULT&0xffff);
}

/**
  * @brief  Returns the CRC validation Result flag
  * @param  None
  * @retval The new state of validation result flag (SET or RESET)
  */
FlagStatus CRC_GetResultFlag(void)
{	
	return ( (CRC_RESULT & CRC_Result_Flag) == CRC_Result_Flag )?  SET : RESET;
}	


/**
  * @}  
  */ 

/**
  * @}  
  */

/**
  * @}  
  */ 

/**
  * @}
  */ 
/************************ (C) COPYRIGHT Giantec Semicondutor Inc *****END OF FILE****/
